SHELL = /bin/bash

IMAGE_PROXY=docker.1ms.run
#SCRIPT_DIR         = $(shell pwd)/etc/script
#请选择golang版本
BUILD_IMAGE_SERVER  = ${IMAGE_PROXY}/golang:1.25
#请选择node版本
BUILD_IMAGE_WEB     = ${IMAGE_PROXY}/node:20
#项目名称
PROJECT_NAME        = abc_hair_salon
#配置文件目录
CONFIG_FILE         = config.yaml
#镜像仓库命名空间
IMAGE_NAME          = abc_hair_salon
REMOTE_REPOSITORY          = registry.cn-hangzhou.aliyuncs.com/zyrzy
#镜像版本
VERSION           ?= latest
# 如何传入自定义版本号：make image VERSION=1.0.0
PLUGIN             ?= email

#容器环境前后端共同打包
#构建web镜像
#${REMOTE_REPOSITORY}/abc_hair_salon-web:1.0.0
build-image-web:
	@cd web/ && DOCKER_BUILDKIT=1 docker build --network=host -t ${IMAGE_NAME}/web:${VERSION} .
	docker tag ${IMAGE_NAME}/web:${VERSION} ${REMOTE_REPOSITORY}/${IMAGE_NAME}-web:${VERSION} 

#构建server镜像
build-image-server:
	@cd server/ && docker build --network=host -t ${IMAGE_NAME}/server:${VERSION} .
	docker tag ${IMAGE_NAME}/server:${VERSION} ${REMOTE_REPOSITORY}/${IMAGE_NAME}-server:${VERSION} 


#打包前后端二合一镜像
image: build-image-web build-image-server

push:
	docker push ${REMOTE_REPOSITORY}/${IMAGE_NAME}-web:${VERSION} 
	docker push ${REMOTE_REPOSITORY}/${IMAGE_NAME}-server:${VERSION} 

#尝鲜版
images: build build-image-web build-image-server
	docker build -t ${REPOSITORY}/all:${VERSION} -f deploy/docker/Dockerfile .

#swagger 文档生成
doc:
	@cd server && swag init

#插件快捷打包： make plugin PLUGIN="这里是插件文件夹名称,默认为email"
plugin:
	if [ -d ".plugin" ];then rm -rf .plugin ; else echo "OK!"; fi && mkdir -p .plugin/${PLUGIN}/{server/plugin,web/plugin} \
	&& if [ -d "server/plugin/${PLUGIN}" ];then cp -r server/plugin/${PLUGIN} .plugin/${PLUGIN}/server/plugin/ ; else echo "OK!"; fi \
	&& if [ -d "web/src/plugin/${PLUGIN}" ];then cp -r web/src/plugin/${PLUGIN} .plugin/${PLUGIN}/web/plugin/ ; else echo "OK!"; fi \
	&& cd .plugin && zip -r ${PLUGIN}.zip ${PLUGIN} && mv ${PLUGIN}.zip ../ && cd ..
